package cn.scu.ne04jdemo.service.imp;

import cn.scu.ne04jdemo.dao.ScheProdTaskInfoMapper;
import cn.scu.ne04jdemo.dao.ScheTaskDevInfoMapper;
import cn.scu.ne04jdemo.entitiy.ScheDevInfoEntity;
import cn.scu.ne04jdemo.entitiy.ScheProdTaskInfoEntity;
import cn.scu.ne04jdemo.entitiy.ScheTaskDevInfoEntity;
import cn.scu.ne04jdemo.service.ScheProdTaskInfoService;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScheProdTaskInfoServiceImpl extends ServiceImpl<ScheProdTaskInfoMapper, ScheProdTaskInfoEntity> implements ScheProdTaskInfoService {
    
    @Autowired
    private ScheProdTaskInfoMapper scheProdTaskInfoMapper;

    @Autowired
    private ScheTaskDevInfoMapper scheTaskDevInfoMapper;


    @Override
//    @Transactional(rollbackFor = Exception.class)
    public Boolean insert(ScheProdTaskInfoEntity scheProdTaskInfoEntity) {
        /**
         * 1.新增产品任务项
         */
        if(!ObjectUtils.isNotNull(scheProdTaskInfoEntity))
            scheProdTaskInfoEntity = new ScheProdTaskInfoEntity();
        this.scheProdTaskInfoMapper.insert(scheProdTaskInfoEntity);
        /**
         * 2.新增任务项与制造单元
         */
        List<ScheTaskDevInfoEntity> scheTaskDevInfoEntityList = this.scheProdTaskInfoMapper.selectScheTaskDevInfo(scheProdTaskInfoEntity.getId());
        for (ScheTaskDevInfoEntity scheTaskDevInfoEntity : scheTaskDevInfoEntityList) {
            this.scheTaskDevInfoMapper.insert(scheTaskDevInfoEntity);
        }

        return true;
    }
}
